package controller;

import service.PickNameServcie;
import service.Impl.PickNameServiceImpl;
import utils.Constants;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.concurrent.ExecutionException;

@WebServlet("/p")
public class PickNameServlet extends HttpServlet {
    /**
     * 随机点名优化版
     */
    private PickNameServcie ps = new PickNameServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String type = req.getParameter("type");
        if (type == null || type.equals("")){
            //type若为空，默认为1
            type = Constants.FAIR;
        }
        //点名的具体逻辑调用
        String s = null;
        try {
            s = ps.pickName(type);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        resp.setContentType("text/html;charset=utf-8");
        resp.getWriter().write(s);
    }
}
